//
//  ZJRoomModelVC.m
//  这家测试项目
//
//  Created by IOS_DEVELOPER on 2017/6/27.
//  Copyright © 2017年 陈志凌. All rights reserved.
//

#import "ZJRoomModelVC.h"
#import "ZJRoomModelDetailVC.h"
#import "ZJRoomModelCell.h"
#import "ZJRoomMoel.h"

@interface ZJRoomModelVC ()<UITableViewDelegate,UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *tableview;
/**<模型数组>*/
@property (nonatomic,strong) NSMutableArray *modelArr;
@end

@implementation ZJRoomModelVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.tableview.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.tableview registerNib:[UINib nibWithNibName:NSStringFromClass([ZJRoomModelCell class]) bundle:nil] forCellReuseIdentifier:@"ZJRoomModelCell"];
    [self sendRequest];
}

#pragma mark - ******************请求数据
-(void)sendRequest{
    [HUD showLoading:@"加载数据中..."];
    NSDictionary *parameter = [LRNetwork requestParameter:@{}];
    NSString *url = [LRNetwork requestURL:@"cgi/model_room.php"];
    
    [LRNetwork netRequestPOSTWithRequestURL:url withParameter:parameter withReturnValeuBlock:^(id returnValue) {
        
        self.modelArr = [ZJRoomMoel mj_objectArrayWithKeyValuesArray:returnValue[@"model"]];
        [self.tableview reloadData];
        [HUD hide];
    } withErrorCodeBlock:^(NSInteger errorCode, NSString *errorMessage) {
        [HUD showErrorMsg:errorMessage];
    } withFailureBlock:^{
        
    }];
}
#pragma mark -UICollectionViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    [tableView tableViewDisplayWitMsg:kNoDataImgName ifNecessaryForRowCount:self.modelArr.count];
    return self.modelArr.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    ZJRoomModelCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ZJRoomModelCell"];
    ZJRoomMoel * model = self.modelArr[indexPath.row];
    cell.model = model;
    cell.topImg.clipsToBounds = YES;
    cell.backgroundColor = [UIColor clearColor];
    cell.selectionStyle = UITableViewCellSelectionStyleNone; 
    [cell useCellFrameCacheWithIndexPath:indexPath tableView:tableView];
    
    return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    CGFloat height = [self.tableview cellHeightForIndexPath:indexPath model:self.modelArr[indexPath.row] keyPath:@"model" cellClass:[ZJRoomModelCell class] contentViewWidth:[Utils cellContentViewWith]];
    
    return height;;
    
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    ZJRoomMoel * model = self.modelArr[indexPath.row];
    ZJRoomModelDetailVC *vc = [[UIStoryboard storyboardWithName:@"Home" bundle:nil] instantiateViewControllerWithIdentifier:@"ZJRoomModelDetailVC"];
    vc.model_id = model.model_id;
    vc.navTitle = model.model_name;
    [self.navigationController pushViewController:vc animated:YES];
}

@end
